package Base.线程的插队;

/**
 * @author 陈鹏
 * join()方法为核心，插队
 * join()方法有无参和有参（long millis）
 */
public class Example10 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1=new Thread(new EmergencyThread(),"thread1");
        thread1.start();
        for (int i=1;i<6;i++){
            System.out.println(Thread.currentThread().getName()+"输入："+i);
            if (i==2){
                //在main线程中调用thread1线程，使得thread1插队运行，main要等到thread1运行完再运行
                thread1.join();
            }
        }
//        thread1.start();
    }
}

class EmergencyThread implements Runnable{
    @Override
    public void run(){
        for (int i=1;i<6;i++){
            System.out.println(Thread.currentThread().getName()+"输入："+i);
        }
    }
}
